#import "FfmpegPlugin.h"
#if __has_include(<ffmpeg_plugin/ffmpeg_plugin-Swift.h>)
#import <ffmpeg_plugin/ffmpeg_plugin-Swift.h>
#else
// Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
#import "ffmpeg_plugin-Swift.h"
#endif

//#import <mobileffmpeg/mobileffmpeg.h>

//extern int ffmpeg_main(int argc, char * argv[]);

@implementation FfmpegPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {

    FfmpegPlugin *p = [[FfmpegPlugin alloc]init];
    
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"ffmpeg_plugin" binaryMessenger:[registrar messenger]];
    [registrar addApplicationDelegate:p];
    [registrar addMethodCallDelegate:p channel:channel];
    
}

-(void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result{
    
    
    //[MobileFFmpeg execute:@"-i file1.mp4 -c:v mpeg4 file2.mp4"];
    
    NSString *methodName = call.method;
    
    NSLog(@"方法：%@ 参数：%@",call.method,call.arguments);
    
    if ([methodName isEqualToString:@"dealWithCommends"]){
        
       // [MobileFFmpeg executeWithArguments:call.arguments];
        
        NSArray *array = call.arguments[@"commend"];
        
        NSLog(@"99999: %@-%@",array[3],array[9]);
        
        [self aaa:array[3] bbb:array[9]];
        
            
    }else if([methodName isEqualToString:@"getVideoInfo"]){
        
       // [MobileFFmpeg execute:@""];
               
    }
    
}

-(void)aaa:(NSString *)videoPath bbb:(NSString *)output{
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        char *movie = (char *)[videoPath UTF8String];
        char *outPic = (char *)[[output stringByAppendingString:@"lm_testVideo.mp4"] UTF8String];

        char* a[] = {
//            "ffmpeg",
            "-ss",
            "00:00:00",
            "-i",
            movie,
            "-t",
            "00:00:20",
            "-c",
            "copy",
            "-copyts",
            outPic
        };
        
        
        //mobileffmpeg_execute(sizeof(a)/sizeof(*a), a);
        
    });

}

//
//-(void)aaa{
//
//    const char * __restrict input_file = "aaa";
//
//    FILE *in_file = fopen(input_file, "rb");
//    // 因为我们在 iOS 工程当中，所以输出路径当然要设置本机的路径了
//    const char* out_file = [[NSTemporaryDirectory() stringByAppendingPathComponent:@"dash.h264"] cStringUsingEncoding:NSUTF8StringEncoding];
//
//
//
//
//}


@end
